package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分类管理查询所有表
     * @param parentId
     * @return
     */
    @GetMapping("/findByParentId/{parentId}")
    public Result findByParentId(@PathVariable("parentId") Long parentId){
        List<Category> categoryList = categoryService.findByParentId(parentId);
        return Result.ok(categoryList);
    }

    /**
     * 导入数据
     * @param multipartFile
     * @return
     */
    @PostMapping("/importData")
    public Result importData(@RequestParam("file")MultipartFile multipartFile){
        categoryService.importData(multipartFile);
        return Result.ok();
    }

    /**
     * 导出功能
     * @param response
     * @return
     */
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }
}
